<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperBean.mapperPackagePath}.${mapperBean.mapperClassName?cap_first}">

  <resultMap id="selectResultMap" type="${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first}">
  	<#--遍历属性集合-->
	<#list beanList as column>
		<result column="${column.columnName}"					jdbcType="${column.mybatisJdbcType}" property="${column.newColumnName}" />
	</#list>
  </resultMap>
  
  <#--查询所有数据-->
  <select id="search4PageList" resultMap="selectResultMap">
  	
  	SELECT 
  			<#--组装查询-->
			<#list beanList as column>
									<#--判断是否已为最后一个元素,最后一个元素不加逗号-->
				${column.columnName}<#if column_has_next>,</#if>
  			</#list>
	FROM ${bean.tableName} 
	<where>
		<#--组装查询条件-->
		<#list beanList as column>
			<#--为查询条件-->
			<#if column.isSelect='1'>
				<#--VARCHAR类型使用模糊查询-->
				<#if column.mybatisJdbcType='VARCHAR'>
					<if test="${column.newColumnName} !=null and ${column.newColumnName} !=''">
						AND	${column.columnName} like concat(concat('%',${r"#"}{${column.newColumnName}}),'%')
					</if>
				<#else>
					<if test="${column.newColumnName} !=null and ${column.newColumnName} !=''">
						AND	${column.columnName}=${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}
					</if>
				</#if>
			</#if>
		</#list>
	</where>
  </select>
  
  <#--查询单条数据-->
  <select id="selectByPrimaryKey" resultType="${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first}">
  	SELECT
  			<#--组装查询-->
			<#list beanList as column>
									<#--判断是否已为最后一个元素,最后一个元素不加逗号-->
				${column.columnName}<#if column_has_next>,</#if>
  			</#list>
	FROM ${bean.tableName}
	<where>
		<#--组装主键-->
		<#list beanList as column>
			<#--为主键-->
			<#if column.isKey='1'>
			 AND	${column.columnName}=${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}
			</#if>
		</#list>
	</where>
  </select>
  
  <#--新增-->
  <insert id="addObject" parameterType="${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first}">
    insert into ${bean.tableName}
    	<trim prefix="(" suffix=")" suffixOverrides="," >
    		<#--组装字段-->
			<#list beanList as column>
				<if test="${column.newColumnName} !=null and ${column.newColumnName} !=''">
								<#--判断是否已为最后一个元素,最后一个元素不加逗号-->
					${column.columnName}<#if column_has_next>,</#if>
				</if>
  			</#list>
      	</trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
    		<#--组装-->
			<#list beanList as column>
				<if test="${column.newColumnName} !=null and ${column.newColumnName} !=''">
					<#--输出'#'号-->														<#--判断是否已为最后一个元素-->
					${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}<#if column_has_next>,</#if>
  				</if>
  			</#list>
      </trim>
  </insert>
  
  <#--修改-->
  <update id="updateByPrimaryKey" parameterType="${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first}">
  		UPDATE ${bean.tableName} 
  		  <set>
  			<#--组装字段-->
			<#list beanList as column>
				<if test="${column.newColumnName} !=null and ${column.newColumnName} !=''">
																										<#--判断是否已为最后一个元素,最后一个元素不加逗号-->
					${column.columnName}=${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}<#if column_has_next>,</#if>
  				</if>
  			</#list>
  		  </set>
  		WHERE 1=1
  			<#--组装主键-->
			<#list beanList as column>
				<#--为主键-->
				<#if column.isKey='1'>
				 AND	${column.columnName}=${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}
				</#if>
			</#list>
  </update>
  
  <#--删除-->
  <delete id="deleteByPrimaryKey" parameterType="${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first}">
  		DELETE FROM ${bean.tableName}
  		WHERE 1=1
  			<#--组装主键-->
			<#list beanList as column>
				<#--为主键-->
				<#if column.isKey='1'>
				 AND	${column.columnName}=${r"#"}{${column.newColumnName},jdbcType=${column.mybatisJdbcType}}
				</#if>
			</#list>
  </delete>
  
</mapper>